<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>错误查询</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<!-- jQuery-->
		<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

		<!-- layui-->
		<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all">
		<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>

		<!-- common -->
		<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
		<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />
		
		
	</head>

	
	<body>

	<!-- 列表 -->
	<div class="layui-row layui-col-space5" style="width:90%;margin: 0 auto;">

		<div class="layui-col-md12" id="id_panel_left_grid">
			<div class="layui-panel" style="overflow: auto; padding-top: 0.2rem;">
				<div class="mid-content">

					<table class="layui-hide" id="main_table" lay-filter="main_table"></table>

					<script type="text/html" id="toolbarDemo">
						<div class="layui-row" style="height: 40px;" id="toolbarDemoBtn">
							<div class="layui-col-xs12">

								<button type="button" class="layui-btn layui-btn-sm" style="margin-left: 0;"  lay-on="save-data">
									<i class="layui-icon layui-icon-ok-circle layui-font-12"></i> 确定
								</button>

							</div>

						</div>
					</script>
					<script type="text/html" id="templet_index_no">{{d.LAY_TABLE_INDEX+1}}</script>
				</div>
			</div>
		</div>
	</div>


      <script>

		  var domForm = $('#' + parent.window.formObj.c.id_form);

		  var sonList = parent.window.formObj.c.subGridObj.c.sonlist ;

		  var dataList = [];
		  if(sonList!=null && sonList.length>0){
			  for(var i=0;i<sonList.length;i++){
			  	var row = sonList[i];
			  	//查询亏损的
			  	if(row['logOrderStatusDz']=='3'){
					dataList.push(row);
				}

			  }
		  }



		  layui.config({
				//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
				base: '/static/js/layui_extends/'
			}).use(['form', 'element', 'table', 'dropdown', 'util', 'laydate', 'upload', 'YsModal'], function(){
					  var element = layui.element;
					  var table = layui.table;
					  var dropdown = layui.dropdown;
					  var form = layui.form;
					  var util = layui.util;
					  var $ = layui.jquery;
					  var laydate = layui.laydate;
					  var upload = layui.upload;

					  //,edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'
			  		  var cols =[ //表头
						  [
							  {title: '', type: 'checkbox',  unresize: true, width: '40'},
							  {title: '序号',   align:"center",type:"numbers"},
                              {title: '物流发票号', width: '160' , field:'logInvoiceNo', align:"center",sort:true},
							  {title: 'FBA编号', width: '160' , field:'fbaNo', align:"center",sort:true},
							  {title: '服务商订单号', width: '160' , field:'spOrderBid', align:"center",sort:true},
							  {title: '服务商物流费用（导入）', width: '160' , field:'spLogsticsFee', align:"center",sort:true},
							  {title: '服务商物流金额（支付）', width: '160' , field:'logSpAmount', align:"center",sort:true},
							  {title: '物流订单利润（对账）', width: '160' , field:'logOrderProfitDz', align:"center",sort:true},
							  {title: '物流服务利润（对账）', width: '160' , field:'logServiceProfitDz', align:"center",sort:true},
							  {title: '物流订单利润率（对账）', width: '160' , field:'logOrderMarginDz', align:"center",sort:true},
							  {title: '物流服务利润率（对账）', width: '160' , field:'logServiceMarginDz', align:"center",sort:true},
							  {title: '物流订单对账状态', width: '160' , field:'logOrderStatusDzTxt', align:"center",sort:true},
							  {title: '本次物流付款金额', width: '160' , field:'payAmount', align:"center",sort:true,edit: 'text',style:'background-color:#E1EFFA;'},
							  {title: '物流订单对账说明', width: '300' , field:'logOrderlDesDz', align:"center",sort:true,edit: 'text',style:'background-color:#E1EFFA;'},
							  {title: '物流发票费用（总）', width: '160' , field:'logInvoiceCost', align:"center",sort:true},
							  {title: '物流销售费用（总）', width: '160' , field:'logInvoiceSalesFee', align:"center",sort:true},
							  {title: '物流渠道名称', width: '160' , field:'logChannelName', align:"center",sort:true},
							  {title: '发货计划', width: '160' , field:'deliverStateTxt', align:"center",sort:true},
							  {title: '运营公司编码', width: '160' , field:'vgsbm', align:"center",sort:true},
							  {title: '运营公司简称', width: '160' , field:'vgsJc', align:"center",sort:true},
							  {title: 'FBA仓库', width: '160' , field:'fbaWarehouse', align:"center",sort:true},
							  {title: 'FBA追踪编号', width: '160' , field:'fbaTrackNo', align:"center",sort:true},
							  {title: 'FBA计划单号', width: '160' , field:'fbaPlanBid', align:"center",sort:true},
							  {title: 'FBA发货单号', width: '160' , field:'fbaDeliverBid', align:"center",sort:true},
							  {title: 'FBA装箱单号', width: '160' , field:'fbaBoxUpBid', align:"center",sort:true},
							  {title: '网店名称', width: '160' , field:'shopName', align:"center",sort:true},
							  {title: '物流服务名称', width: '160' , field:'logsticsWay', align:"center",sort:true},
							  {title: '是否报关', width: '160' , field:'declarationStateTxt', align:"center",sort:true},



						  ]
					  ];
					  // 创建渲染实例
					  table.render({
						  id:'main_table'
						  ,elem: '#main_table'
						  ,data:dataList
						  ,toolbar: '#toolbarDemo'
						  ,defaultToolbar: [ 'filter',{
							  title: '刷新页面'
							  ,layEvent: 'LAYTABLE_REFRESH'
							  ,icon: 'layui-icon-refresh'
						  }]
						  ,height: window.innerHeight - 70 // 最大高度减去其他容器已占有的高度差
						  ,where: {}
						  ,cellMinWidth: 95
						  ,limit : 200
						  ,limits : [20,50,200,500]
						  ,page: true
						  ,request: {
							  pageName: 'page',
							  limitName: 'size'
						  }
						  //,skin: 'row'
						  ,even: false // 开启隔行背景
						  ,skin: 'grid'//设置表格边框风格
						  ,cols:cols
						  ,done: function(res){

						  }
						  ,error: function(res, msg){
							  console.log(res, msg)
						  }
					  });

					  // 单元格编辑事件
					  table.on('edit(main_table)', function(obj){
						  var field = obj.field; // 得到修改的字段
						  var value = obj.value; // 得到修改后的值
						  var data = obj.data; // 得到所在行所有键值
						  //console.log(obj); // 查看对象所有成员
						  //console.log('----- dataList ------',dataList);
						  // 更新当前缓存数据
						  var update = {};
						  update[field] = value;
						  obj.update(update, true); // 参数 true 为 v2.7 新增功能，即同步更新其他包含自定义模板并可能存在关联的列视图
					  });

					  // 工具栏事件
					  table.on('toolbar(main_table)', function(obj){
						  var id = obj.config.id;
						  var checkStatus = table.checkStatus(id);
                          var datas = checkStatus.data;
						  var othis = lay(this);
						  switch(obj.event){
                              case 'LAYTABLE_REFRESH':
							  {
								  layer.confirm("确定刷新吗？",{
									  btn: ['确定', '取消']
								  }, function (index) {
									  location.reload();
									  layer.close(index);
								  });
								  break;
							  }

						  };
					  });

					  // 普通事件
					  util.on('lay-on', {
						  //保存
						  "save-data": function(){
							  toAdd();
						  },
                          /*
                          "edit-data": function(){
                              toAdd();
                          },

                           */


					  })

				  });


		  //确定
		  function toAdd() {
			  ///var sonList = parent.window.formObj.c.subGridObj.c.sonlist
		  	if(dataList!=null && dataList.length>0){
		  		for(var i=0;i<dataList.length;i++){
		  			var dataRow = dataList[i];
		  			for(var j=0;j<sonList.length;j++){
		  				if(dataRow['logInvoiceNo'] == sonList[j]['logInvoiceNo']){
							sonList[j] = dataRow;
						}
					}

				}


				//计算总金额
				var amount = 0 ;//总金额
				if(sonList!=null && sonList.length>0){
					for(var i=0;i<sonList.length;i++){
						if(sonList[i].payAmount){
							amount = amount+parseFloat(sonList[i].payAmount);
						}
					}
				}
				//回填总金额
				domForm.find('input[name="totalAmount"]').val(amount.toFixed(2));

				parent.window.formObj.c.subGridObj.c.sonlist = sonList;
				parent.window.formObj.c.subGridObj.reloadGrid();
				parent.window.layer.closeAll();
			}


		  }



      </script>

  </body>
</html>